package com.xluomo.notification_listen_service_plugin;

import android.content.ComponentName;
import android.content.Context;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;

public class NotificationListenUtil {

    public static boolean isPermissionGranted(Context context) {
        String packageName = context.getPackageName();
        String flat = Settings.Secure.getString(context.getContentResolver(), "enabled_notification_listeners");
        if (!TextUtils.isEmpty(flat)) {
            String[] names = flat.split(":");
            for (String name : names) {
                if (!name.isEmpty()) {
                    ComponentName componentName = ComponentName.unflattenFromString(name);
                    boolean nameMatch = TextUtils.equals(packageName, componentName.getPackageName());
                    if (nameMatch) {
                        return true;
                    }
                }
            }
        }
        return false;
    }
}
